package logintest.login.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import logintest.login.pojo.UserInfoEntity;
import logintest.login.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/userInfo")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    //根据id获取用户信息
    public UserInfoEntity getInfo(Long id) {
        UserInfoEntity byId = userInfoService.getById(id);
        return byId;
    }

    @RequestMapping("/getList")
    public List<UserInfoEntity> getList() {
        List<UserInfoEntity> list = userInfoService.list();
        return list;
    }

    @RequestMapping("/getIfoListPage")
    public IPage<UserInfoEntity> getInfoListPage() {
        IPage<UserInfoEntity> page = new Page<>();
        page.setCurrent(5);//当前页数
        page.setSize(1);//每页条数
        page = userInfoService.page(page);
        return page;
    }
    @RequestMapping("getListMap")
    public Collection<UserInfoEntity> getListMap(){
        Map<String, Object> map = new HashMap<>();
        map.put("age",20);
        Collection<UserInfoEntity> userInfoEntities = userInfoService.listByMap(map);
        return userInfoEntities;
    }
    //新增用户信息
    @RequestMapping("/saveInfo")
    public void saveInfo(UserInfoEntity userInfoEntity){
        UserInfoEntity userInfoEntity1 = new UserInfoEntity();
        userInfoEntity1.setId(userInfoEntity.getId());
        userInfoEntity1.setPassword(userInfoEntity.getPassword());
        userInfoEntity1.setAge(userInfoEntity.getAge());
        userInfoEntity1.setName(userInfoEntity.getName());
        userInfoEntity1.setTel(userInfoEntity.getTel());
    }
    //批量新增用户信息
    @RequestMapping("/saveInfoList")
    public void saveInfoList(ArrayList<UserInfoEntity> list){
        for (int i = 0; i < list.size(); i++) {
            saveInfo(list.get(i));
        }
    }


}
